package _021_10_4

import "strings"

//*| b| c|*| b|c |*| b| |*| | |*

func countSegments(s string) int {
	s = strings.ToUpper(s)
	s2 := []byte(s)
	strId := 0
	wordNum := 0
	for strId < len(s2) {
		if isAlpha(s2[strId]) {
			wordNum++
			isWord(s2, &strId)
		}
		strId++
	}
	return wordNum
}

func isWord(b []byte, strId *int) {
	for ; *strId < len(b); *strId++ {
		if !isAlpha(b[*strId]) {
			return
		}
	}
}

func isAlpha(c byte) bool {
	if 'A' <= c && c <= 'Z' || c == '\'' || c == '-' {
		return true
	}
	return false
}

func countSegments2(s string) int {
	strId := 0
	wordN := 0
	for {
		if s[strId] != ' ' {
			break
		}
		strId++
	}
	s2 := []byte(s)
	s2 = s2[strId:]
	if s2[len(s2)-1] == ' ' {
		s2 = s2[0 : len(s2)-1]
	}

	for i := 0; i < len(s2); i++ {
		if s2[i] == ' ' {
			wordN++
		}
	}
	return wordN
}
